home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Examples / Example External Tools / ProcessTool / Request.cp < prev    next >
Encoding:
Text File  |  1998-06-04  |  8.1 KB  |  285 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    File:        Request.cp
  3.  *
  4.  *    Contains:    xxx put contents here xxx
  5.  *
  6.  *    Written by:    Rick Violet
  7.  *
  8.  *    Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  9.  *
  10.  *    Change History (most recent first):
  11.  *
  12.  *         <2>     1/28/94    CMW        String utilities have moved to TextUtils.h.
  13.  *                11/18/92    RV        xxx put comment here xxx
  14.  *
  15.  *    To Do:
  16.  */
  17.  
  18. #ifndef        __Request__
  19. #include        "Request.h"
  20. #endif
  21.  
  22. #ifndef        __RequestDispatcher__
  23. #include        "RequestDispatcher.h"
  24. #endif
  25.  
  26. #ifndef        __ERRORS__
  27. #include        <Errors.h>
  28. #endif
  29.  
  30. #ifndef        __TEXTUTILS__
  31. #include        <TextUtils.h>
  32. #endif
  33.  
  34. //—————————————————————————————————————————————————————————————————————————————————————
  35. //                                Global Variables
  36. //—————————————————————————————————————————————————————————————————————————————————————
  37. extern    RequestDispatcher*        gTheRequestDispatcher;
  38.  
  39. //—————————————————————————————————————————————————————————————————————————————————————
  40. //    Request::Request    -    constructor.
  41. //—————————————————————————————————————————————————————————————————————————————————————
  42. Request::Request()
  43. {
  44.     fWhichService         = nil;            //————    No Request name yet
  45.     fParamList             = nil;            //————    create empty list of parameters
  46.     fReturnValue         = nil;            //————    create empty return value
  47.     fErrorCode             = noErr;        //————    No errors yet
  48.     fErrorMessage         = nil;            //————    No error message yet
  49.     fCanceled             = false;        //————    Not canceled yet
  50.     fRequestIdentifier     = 0;            //————    No identifier yet
  51.     fSendResetTicks        = TickCount();    //————    Set to current Ticks
  52. }
  53.  
  54. //—————————————————————————————————————————————————————————————————————————————————————
  55. //    Request::~Request    -    destructor.
  56. //—————————————————————————————————————————————————————————————————————————————————————
  57. Request::~Request()
  58. {
  59.         //————    dispose of fWhichService 
  60.     if( fWhichService != nil )
  61.     {
  62.         delete fWhichService;
  63.     }
  64.  
  65.         //————    dispose of fParamList 
  66.     if( fParamList != nil )
  67.     {
  68.         delete fParamList;
  69.     }
  70.  
  71.         //————    dispose of fReturnValue 
  72.     if( fReturnValue != nil )
  73.     {
  74.         delete fReturnValue;
  75.     }
  76.  
  77.         //————    dispose of fErrorMessage 
  78.     if( fErrorMessage != nil )
  79.     {
  80.         delete fErrorMessage;
  81.     }
  82. }
  83.  
  84. //—————————————————————————————————————————————————————————————————————————————————————
  85. //    Request::Initialize    -    initialize the Request
  86. //—————————————————————————————————————————————————————————————————————————————————————
  87. OSErr
  88. Request::Initialize()
  89. {
  90.         //————    Tell V.U. not to time out for at least kDefaultTimeOutSeconds
  91.     ResetTimeOutCounter();    
  92.         
  93.     return noErr;
  94. }
  95.  
  96. //—————————————————————————————————————————————————————————————————————————————————————
  97. //    Request::HasBeenCanceled    - Check to see if this command has been canceled
  98. //—————————————————————————————————————————————————————————————————————————————————————
  99. Boolean
  100. Request::HasBeenCanceled()
  101. {
  102.     return fCanceled; 
  103. }
  104.  
  105. //—————————————————————————————————————————————————————————————————————————————————————
  106. //    Request::ResetTimeOutCounter - inform V.U. to not let this Request
  107. //—————————————————————————————————————————————————————————————————————————————————————
  108. void
  109. Request::ResetTimeOutCounter( unsigned long pNewTimeOutInterval )
  110. {    
  111.         //————    Set up the Time Manager task to fire again at a later time
  112.     if( !HasBeenCanceled() )
  113.     {
  114.             //————    Keep Track of when we'll time out
  115.         fSendResetTicks = TickCount() + (pNewTimeOutInterval * 60);
  116.     }
  117. }
  118.  
  119. //—————————————————————————————————————————————————————————————————————————————————————
  120. //    Request::IsACancelRequest    - Is this a Cancel Request?
  121. //                                    return true if this is a cancel service request
  122. //—————————————————————————————————————————————————————————————————————————————————————
  123. Boolean
  124. Request::IsACancelRequest()
  125. {
  126.     if( relstring( fWhichService, (char*)kVUAECancelService, false, true ) == 0 )
  127.     {
  128.         return true;
  129.     }
  130.     else
  131.     {
  132.         return false;
  133.     }
  134. }
  135.  
  136. //—————————————————————————————————————————————————————————————————————————————————————
  137. //    Request::IsCancelRequestForThisRequest    - is the cancel request
  138. //        passed in as a parameter for canceling this sevice request object
  139. //—————————————————————————————————————————————————————————————————————————————————————
  140. Boolean
  141. Request::IsCancelRequestForThisRequest( Request* pCancelReq )
  142. {
  143.     long    tReqID;
  144.     
  145.         //————    Get the Identifier of the request to cancel 
  146.         //————    from the Cancel Request object
  147.     tReqID = pCancelReq->GetIdentifierOfRequesttoCancel();
  148.     if( tReqID == fRequestIdentifier )
  149.     {
  150.         return true;
  151.     }
  152.     else
  153.     {
  154.         return false;
  155.     }
  156. }
  157.  
  158. //—————————————————————————————————————————————————————————————————————————————————————
  159. //    Request::SetErrorCode    - set the Error code for this request
  160. //—————————————————————————————————————————————————————————————————————————————————————
  161. void
  162. Request::SetErrorCode( OSErr tErr )
  163. {
  164.     fErrorCode = tErr;
  165. }
  166.  
  167. //—————————————————————————————————————————————————————————————————————————————————————
  168. //    Request::SetErrorMessage    - set the Error message for this request
  169. //—————————————————————————————————————————————————————————————————————————————————————
  170. void
  171. Request::SetErrorMessage( char* tErrText )
  172. {
  173.         //————    Keep Request status in sync with the error code
  174.     fErrorMessage = new char[ strlen( tErrText ) + 1];
  175.     if( fErrorMessage )
  176.     {
  177.         strcpy( fErrorMessage, tErrText );
  178.     }
  179. }
  180.  
  181. //—————————————————————————————————————————————————————————————————————————————————————
  182. //    Request::GetNthParam    -    get the Nth parameter
  183. //—————————————————————————————————————————————————————————————————————————————————————
  184. OSErr
  185. Request::GetNthParam( short pIndex, ScriptValuePtr& pValue, ValueKind& pVKind )
  186. {    
  187.     if( fParamList != nil )
  188.     {
  189.         return fParamList->GetNthItem( pIndex, pValue, pVKind ); 
  190.     }
  191.     else
  192.     {
  193.         pVKind = kVUAnyKind;
  194.         pValue = nil;
  195.         return errAEWrongParameters;
  196.     }
  197. }
  198.  
  199. //—————————————————————————————————————————————————————————————————————————————————————
  200. //    Request::GetParamCount    -    return the number of parameters
  201. //—————————————————————————————————————————————————————————————————————————————————————
  202. short
  203. Request::GetParamCount()
  204. {
  205.     if( fParamList != nil )
  206.     {
  207.         return fParamList->GetCount();
  208.     }
  209.     else
  210.     {
  211.         return 0;
  212.     }
  213. }
  214.  
  215. //—————————————————————————————————————————————————————————————————————————————————————
  216. //    Request::SetReturnValue    -    set the return value for this request
  217. //                                        to a Number ScriptValue
  218. //—————————————————————————————————————————————————————————————————————————————————————
  219. void
  220. Request::SetReturnValue( short pNumber )
  221. {
  222.     ScriptValue*    tVal;
  223.     
  224.     tVal = new VUNumber( pNumber );
  225.     fReturnValue = tVal; 
  226. }
  227.  
  228. //—————————————————————————————————————————————————————————————————————————————————————
  229. //    Request::SetReturnValue    -    set the return value for this request
  230. //                                        to a Number ScriptValue
  231. //—————————————————————————————————————————————————————————————————————————————————————
  232. void
  233. Request::SetReturnValue( long pLongNumber )
  234. {
  235.     ScriptValue*    tVal;
  236.     
  237.     tVal = new VULongNumber( pLongNumber );
  238.     fReturnValue = tVal; 
  239. }
  240.  
  241. //—————————————————————————————————————————————————————————————————————————————————————
  242. //    Request::SetReturnValue    -    set the return value for this request
  243. //                                        to a Boolean ScriptValue
  244. //—————————————————————————————————————————————————————————————————————————————————————
  245. void
  246. Request::SetReturnValue( Boolean pFlag )
  247. {
  248.     ScriptValue*    tVal;
  249.     
  250.     tVal = new VUBoolean( pFlag );
  251.     fReturnValue = tVal; 
  252. }
  253.  
  254. //—————————————————————————————————————————————————————————————————————————————————————
  255. //    Request::SetReturnValue    -    set the return value for this request
  256. //                                        to a String ScriptValue
  257. //—————————————————————————————————————————————————————————————————————————————————————
  258. void
  259. Request::SetReturnValue( char* pString )
  260. {
  261.     ScriptValue*    tVal;
  262.     
  263.     tVal = new VUString( pString );
  264.     fReturnValue = tVal; 
  265. }
  266.  
  267. //—————————————————————————————————————————————————————————————————————————————————————
  268. //    Request::SetReturnValue    -    set the return value for this request
  269. //                                        to a String ScriptValue
  270. //—————————————————————————————————————————————————————————————————————————————————————
  271. void
  272. Request::SetWhichService( char* pServiceText )
  273. {
  274.     fWhichService = new char[ strlen( pServiceText ) + 1 ];
  275.     if( fWhichService == nil )
  276.     {
  277.         SetErrorCode( memFullErr );
  278.         SetErrorMessage( "Failed to allocate string for Request object." );
  279.     }
  280.     else
  281.     {
  282.         strcpy( fWhichService, pServiceText );
  283.     }
  284. }
  285.